# Steps to run this example:
#
# (1) Run the following commands locally to get the example input image.
#       mkdir -p ~/Downloads/detectron-inputs
#       wget http://images.cocodataset.org/val2017/000000439715.jpg -O ~/Downloads/detectron-inputs/input.jpg
#
# (2) Change L18 to a unique bucket name to create a private bucket.

resources:
  accelerators: V100:4

file_mounts:
  # TODO: run the download commands above first.
  /inputs: ~/Downloads/detectron-inputs
  /detectron2: ./examples/docker/detectron2
  /outputs:
    # TODO: Change the name to your own bucket name (e.g., append your user name).
    name: sky-detectron2-outputs
    mode: MOUNT


setup: |
  # Build:
  sudo apt update
  docker build --build-arg USER_ID=$UID -t detectron2:v0 /detectron2

run: |
  # Launch (require GPUs):
  docker run -a stdout -a stderr --gpus=all --pid=host --rm \
    --shm-size=8gb \
    --volume=$HOME/.torch/fvcore_cache:/tmp:rw \
    --volume="/inputs:/inputs:ro" \
    --volume="/outputs:/outputs:rw" \
    detectron2:v0 /bin/bash -c \
    "echo CUDA_VISIBLE_DEVICES $CUDA_VISIBLE_DEVICES && \
    sudo chmod -R 777 /tmp && \
    python3 demo/demo.py  \
      --config-file configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml \
      --input /inputs/input.jpg --output /outputs \
      --opts MODEL.WEIGHTS detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl"
